package org.tekmob.remindpal;

import java.util.ArrayList;

import org.tekmob.remindpal.model.Info;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
 * This activity will be called to set Reminder Details
 * 
 * @author Annisa
 */
public class MyArrayAdapter extends ArrayAdapter<Info> {

	Context context;
	int layoutResourceId;
	ArrayList<Info> Infos = new ArrayList<Info>();

	public MyArrayAdapter(Context context, int layoutResourceId,
			ArrayList<Info> info) {
		super(context, layoutResourceId, info);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.Infos = info;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View item = convertView;
		InfoWrapper InfoWrapper = null;

		if (item == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			item = inflater.inflate(layoutResourceId, parent, false);
			InfoWrapper = new InfoWrapper();
			InfoWrapper.title = (TextView) item.findViewById(R.id.textTitle);
			InfoWrapper.detail = (TextView) item.findViewById(R.id.textDetail);

			item.setTag(InfoWrapper);
		} else {
			InfoWrapper = (InfoWrapper) item.getTag();
		}

		Info Info = Infos.get(position);
		InfoWrapper.title.setText(Info.getTitle());
		InfoWrapper.detail.setText(Info.getDetail());

		return item;

	}

	static class InfoWrapper {
		TextView title;
		TextView detail;
	}

}
